package com.ruoyi.wretchant.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wretchant.domain.MetaBookReadNote;
import com.ruoyi.wretchant.service.IMetaBookReadNoteService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 读书笔记Controller
 * 
 * @author 简简单单 Online zuozuo
 * @date 2021-08-15
 */
@Controller
@RequestMapping("/wretchant/readnote")
public class MetaBookReadNoteController extends BaseController
{
    private String prefix = "wretchant/readnote";

    @Autowired
    private IMetaBookReadNoteService metaBookReadNoteService;

    @RequiresPermissions("wretchant:readnote:view")
    @GetMapping()
    public String readnote()
    {
        return prefix + "/readnote";
    }

    /**
     * 查询读书笔记列表
     */
    @RequiresPermissions("wretchant:readnote:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MetaBookReadNote metaBookReadNote)
    {
        startPage();
        List<MetaBookReadNote> list = metaBookReadNoteService.selectMetaBookReadNoteList(metaBookReadNote);
        return getDataTable(list);
    }

    /**
     * 导出读书笔记列表
     */
    @RequiresPermissions("wretchant:readnote:export")
    @Log(title = "读书笔记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MetaBookReadNote metaBookReadNote)
    {
        List<MetaBookReadNote> list = metaBookReadNoteService.selectMetaBookReadNoteList(metaBookReadNote);
        ExcelUtil<MetaBookReadNote> util = new ExcelUtil<MetaBookReadNote>(MetaBookReadNote.class);
        return util.exportExcel(list, "读书笔记数据");
    }

    /**
     * 新增读书笔记
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存读书笔记
     */
    @RequiresPermissions("wretchant:readnote:add")
    @Log(title = "读书笔记", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MetaBookReadNote metaBookReadNote)
    {
        return toAjax(metaBookReadNoteService.insertMetaBookReadNote(metaBookReadNote));
    }

    /**
     * 修改读书笔记
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MetaBookReadNote metaBookReadNote = metaBookReadNoteService.selectMetaBookReadNoteById(id);
        mmap.put("metaBookReadNote", metaBookReadNote);
        return prefix + "/edit";
    }

    /**
     * 修改保存读书笔记
     */
    @RequiresPermissions("wretchant:readnote:edit")
    @Log(title = "读书笔记", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MetaBookReadNote metaBookReadNote)
    {
        return toAjax(metaBookReadNoteService.updateMetaBookReadNote(metaBookReadNote));
    }

    /**
     * 删除读书笔记
     */
    @RequiresPermissions("wretchant:readnote:remove")
    @Log(title = "读书笔记", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(metaBookReadNoteService.deleteMetaBookReadNoteByIds(ids));
    }
}
